#include <stdio.h>
#include <stdlib.h>
#include <conio.h> 
#include <math.h>
void br(int lines = 1) {
	for(int i = 0; i < lines; i++) printf("\n");
}

float summa (float arr[],int n){

	int i;

	float summ = 0;
	for (i = 0; i < n; i ++)
		summ += arr[i];
	return summ;

}

void printm(int n,float mass[])
{
	int i;
	for(i = 0; i < n; i++){
		printf("%f	", mass[i]);
	}
}

float maximum(float ch[],int n)
{
	float max=0;
	int i;
	for (i=0;i<n;i++)
	{
		if (ch[i]>max) max=ch[i];
	}

	return max;
}

float minimum(float ch[],int n)
{
	int i;
	float min=ch[1];

	for (i=0;i<n;i++)
	{
		if (ch[i]<min) min=ch[i];
	}
	return min;
}

float srednee(float arr[],int n)
{

	float sr;


	sr = summa(arr, n)/n;
	return sr;
}

void uporyadochivanie (float mass[],int n)
{
	int j,i;
	float r;

	for (j=n-2; j>=0; j--)	
		for (i=j; i<n-1; i++)
			if (mass[i] > mass[i+1]) {
				r=mass[i+1];
				mass[i+1]=mass[i];
				mass[i]= r;  
			} else break;

	printm(n,mass);
}

float mediana(float arr[],int n)
{
	float med;

	uporyadochivanie (arr,n);

	med=arr[(int) floor((float) n/2)];
	return med;


}

float srkv( float ch[],int n)
{
	int i;
	
	float srkv=0;
	float srkv1;
	float sred = srednee(ch, n);

	for (i=0;i<n;i++)		srkv=srkv+(ch[i]-sred)*(ch[i]-sred);

	srkv1=sqrt(srkv/n);

	return srkv1;
}

int odinakovue(float ch[],int n)
{
	int j;
	int i;

	int ravnmax = 0;
	float ravn[1000];

	for (i=0;i<n;i++)
	{
		ravn[i]=0;
		for (j=i;j<n;j++)
		{
			if (ch[i]==ch[j])
			{
				ravn[i]=ravn[i]+1;
			}
			else break;							
		}			

	}		
	ravnmax = 0;
	for(i = 0; i < n; i++) {
		if(ravn[i] > ravnmax) ravnmax = ravn[i];
	}
	return ravnmax;
}

int vozvrastanie (float ch[], int n)
{
	int j,i;
	int v[100],v1[100],vm,vm1;

	for (i=0;i<n;i++) v[i]=1;
	for (i=0;i<n;i++)
	{
		for (j=i+1;j<n;j++)
		{
			if (ch[j]>=ch[j-1])
			{
				v[i]=v[i]+1;
			}
			else break;							
		}			
	}


	vm=v[1];
	for (i=1;i<n;i++)
	{
		if(v[i]>vm) vm=v[i];
	}


	for (i=1;i<n;i++) v1[i]=1;
	for (i=1;i<n;i++)
	{
		for (j=i+1;j<n;j++)
		{
			if (ch[j]<=ch[j-1])
			{
				v1[i]=v1[i]+1;
			}
			else break;							
		}			
	}
	vm1=v1[1];
	for (i=1;i<n;i++)
	{
		if(v1[i]>vm1) vm1=v1[i];
	}
	if (vm1>vm) vm=vm1;
	return vm;
}

void main()
{
	int r,i,n=0;

	float ch[100000],ch1[100000];		
	float sr;

	printf("vvedite chisla cherez probel,  v konce nagmite enter\n");

	for (i = 0; i < 100000; i++){
		r = scanf(" %f", &ch[i]);
		if (r==0) break;
		n++;
	}
	for(i=0;i<n;i++){
		
		ch1[i]=ch[i];
	}

	br();

	printf("poluchennuy massiv"); br();
	printm(n,ch); br(2);

	printf("uporyadochim nash massiv"); br();
	uporyadochivanie(ch1,n); br(2);

	printf("naydem maximum \n %f",maximum(ch,n)); br();
	br(2);


	printf("naydem minimum\n %f", minimum(ch,n)); br();
	br(2);

	printf("naydem srednee \n %f",  srednee(ch, n)); br();
	br(2);

	printf("naydem medianu massiva \n ");
	if (n%2==0) 
		printf("medianu net");
	else
		printf(" mediana = %f", mediana(ch1,n));
	br();
	br(2);

	printf("naydem srednekvadrotuchnoe otklonenie \n %f", srkv(ch,n));
	br(2);

	printf("naydem dlinu maximal'nogo uchastka odinakovuh chisel\n");
	printf("maximal'naya dlina = %d \n ",odinakovue(ch,n));	br();

	printf("naydem dlinu maximal'nogo uchastka monotonnosti\n");
	printf("maximal'naya dlina = %d \n",vozvrastanie(ch,n));	br();


	system("pause");
}


